import request from "../../utils/request";
import {RoleObj} from "../../types/tanTypes/role";

// 添加角色
export const addRole = (RoleObj: RoleObj) => {
    console.log(RoleObj)
    return request.post('classes/roleTable', RoleObj)
}

// 查询角色
export const getUser = (name: string = '') => {
    if (name === '') {
        return request.get('classes/roleTable', )
    }else {
        return request.get('classes/roleTable', {
            params: {
                where: {
                    roleName: name
                }
            }
        })
    }

}

// 删除角色
export const deleteRole = (key: string) => {
    console.log(key)
    return request.delete(`classes/roleTable/${key}`)
}

// 修改角色
export const updateRole = (id: string, upObj: RoleObj) => {
    return request.put(`classes/roleTable/${id}`, upObj)
}

// 获取用户
export const getUsers = () => {
    return request.get('users')
}

// 注册权限用户
interface regObj {
    username: string;
    password: string;
    role: string;
}
export const registerRole = (obj: regObj) => {
    return request.post('users', obj)
}
